<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单管理-车速递</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../css/mymain.mymain.css">
    <script type="application/javascript" src="../js/jquery-3.3.1.js"></script>
    <script type="application/javascript" src="../js/bootstrap.min.js"></script>
    <script type="application/javascript" src="../layui/layui.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>

</head>
<body style="position: static">

    <div id="updateUser" style="display: none; padding: 20px">
        <form id="updateUserForm" class="layui-form layui-form-pane" lay-filter="updateProductForm">
            <div class="layui-form-item" style="display: none;">
                <label class="layui-form-label">编号</label>
                <div class="layui-input-block">
                    <input type="text" name="uid" id="uid" class="layui-input" readonly>
                </div>
            </div>
            <div class="layui-form-item" id="nameDiv">
                <label class="layui-form-label">账号名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" class="layui-input" lay-verify="required" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item" id="emailDiv">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input type="text" name="email" id="email" class="layui-input" lay-verify="required" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="updateUserBtn">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>

    <div id="passForm" style="display: none; padding: 20px">
        <form id="updatePassForm" class="layui-form layui-form-pane" lay-filter="updateProductForm">
            <div class="layui-form-item" id="passDiv">
                <label class="layui-form-label">原密码</label>
                <div class="layui-input-block">
                    <input type="text" name="pass" id="pass" class="layui-input" lay-verify="required" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item" id="newPassDiv">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                    <input type="text" name="newPass" id="newPass" class="layui-input" lay-verify="required" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item" id="newrePassDiv">
                <label class="layui-form-label">密码确认</label>
                <div class="layui-input-block">
                    <input type="text" name="newrePass" id="newrePass" class="layui-input" lay-verify="required" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="updatePassBtn">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>

    <div id="app" class="bgGray">
        <div data-v-95ac8d30="" class="header3">
            <div data-v-95ac8d30="" class="layout clear">
                <div data-v-95ac8d30="" class="left logo">
                    <a data-v-95ac8d30="" href="index.html">
                        <img data-v-95ac8d30="" src="">
                    </a>
                </div>
                <div data-v-95ac8d30="" class="header3Nav right">
                    <a data-v-95ac8d30="" href="/pagehome/index.html">首页</a>
                    |<a data-v-95ac8d30="" href="/mymain/mymain.html">我的订单</a>
                    |<a data-v-95ac8d30="" href="helpCenter.html">帮助中心</a>
                    |<a data-v-95ac8d30="" href="/pagehome/index.html" onclick="exitLogin()" id="exitLogin">退出</a>
                </div>
                <div data-v-95ac8d30="" class="header3User right">
                    <i data-v-95ac8d30="" class="iconfont icon-phone"></i>
                    <span data-v-95ac8d30="" class="sp1" id="telSpan">400-919-8000</span>
                    <span data-v-95ac8d30="" class="sp2">欢迎您，</span>
                    <span data-v-95ac8d30="" class="sp3" id="nameSpan"></span>
                </div>
            </div>
        </div>
        <div class="userInfo">
            <div class="layout">
                <div class="userInfoCom clear">
                    <div class="userInfoL left">
                        <div data-v-1cae2c34="" class="userNav">
                            <dl data-v-1cae2c34="" class="userMsg">
                                <dt data-v-1cae2c34="">
                                    <img data-v-1cae2c34="" src="">
                                </dt>
                                <dd data-v-1cae2c34="">
                                    <p data-v-1cae2c34=""></p>
                                    <p data-v-1cae2c34="" class="p5 pp" style="">普卡会员</p>
                                </dd>
                            </dl>
                            <ul data-v-1cae2c34="" class="manNav">
                                <li data-v-1cae2c34="">
                                    <a data-v-1cae2c34="" href="mymain.html" class="">订单管理</a>
                                </li>
                                <li data-v-1cae2c34="">
                                    <a data-v-1cae2c34="" href="myinfo.html" class="sel">个人信息</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div class="userInfoR right">

                        <div class="orderManage manage">
                            <div class="orderManageTit manageTit clear">
                                <div class="left tit">个人信息</div>
                            </div>
                            <div class="site-demo-button" id="layerDemo" style="margin-bottom: 0;">
                                <div class="orderList list" id="noda">
                                    <table class="tableinfo" id="updateTable" lay-filter="updateTable">
                                        <tr>
                                            <td>手机号：</td>
                                            <td id="telTd"></td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td>账号名：</td>
                                            <td id="nameTd"></td>
                                            <td><button id="updateName" data-method="offset" data-type="auto" class="layui-btn layui-btn-normal">修改</button></td>
                                        </tr>
                                        <tr>
                                            <td>邮箱：</td>
                                            <td id="emailTd"></td>
                                            <td><button id="updateEmail" data-method="offset" data-type="auto" class="layui-btn layui-btn-normal">修改</button></td>
                                        </tr>
                                        <tr>
                                            <td></td>
                                            <td></td>
                                            <td>
                                                <a href="#" style="color: orangered" id="updatePass">修改密码</a>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div data-v-3aaf9db2="" class="footer2">
            <div data-v-3aaf9db2="" class="layout clear">
                <div data-v-3aaf9db2="" class="d1">
                    <a data-v-3aaf9db2="" href="about.html">关于车速递</a></div></div></div>
    </div>

    <script>
        var storage = window.sessionStorage;

        layui.use(['jquery', 'table', 'layer', 'form'], function () {
            // 加载layui模块，使用其推荐的【预先加载】方式，详见官网【模块规范】一节
            var $ = layui.$;
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;

            function flushPage(){
                //重新获取user数据
                $.ajax({
                    url: "/getLoginUser",
                    type: "GET",
                    contentType: 'application/json',
                    dataType: 'json',
                    success: function(data) {
                        console.log(data);
                        data = JSON.stringify(data);
                        storage.setItem('user', data);
                        var u = JSON.parse(storage.getItem('user'));
                        $("#nameSpan").text(u.name);
                        $("#telSpan").text(u.tel);
                        $("#nameTd").text(u.name);
                        $("#telTd").text(u.tel);
                        $("#emailTd").text(u.email);
                    },
                    error: function() {
                        console.log("ajax error");
                    }
                });
            }

            //将user的json串转化为对象
            var user = JSON.parse(storage.getItem('user'));
            if (user != null) {
                $("#nameSpan").text(user.name);
                $("#telSpan").text(user.tel);
                $("#nameTd").text(user.name);
                $("#telTd").text(user.tel);
                $("#emailTd").text(user.email);
            } else {
                $("#successLobel").hide();
            }

            $("#updateName").click(function (){
                update('nameDiv');
            });

            $("#updateEmail").click(function (){
                update('emailDiv');
            });

            //修改密码
            $("#updatePass").click(function (){
                //打开窗口
                layer.open({
                    type: 1,
                    title: '修改密码',
                    // skin: 'layui-layer-molv',
                    area: ['500px'],
                    content: $('#passForm')
                });
            });

            function update(column){
                //页面元素展示
                $("#nameDiv").hide();
                $("#emailDiv").hide();
                $("#" + column).show();
                //打开窗口
                layer.open({
                    type: 1,
                    title: '修改信息',
                    area: ['500px'],
                    content: $('#updateUser')
                });
                //加载数据
                $("#name").val(user.name);
                $("#email").val(user.email);
                $("#uid").val(user.uid);
            }

            //修改普通字段
            form.on('submit(updateUserBtn)', function(data) {
                $.ajax({
                    url: "/updateUser",
                    type: "POST",
                    data: JSON.stringify(data.field),
                    contentType: 'application/json',
                    dataType: 'json',
                    success: function(data) {
                        if (data) {
                            layer.close(layer.index);
                            layer.msg('修改成功');
                            flushPage();
                            table.reload('updateTable');
                           // setTimeout('window.location.reload()',1000);
                        } else {
                            layer.msg('修改失败');
                        }
                    },
                    error: function() {
                        console.log("ajax error");
                    }
                });
                // 阻止表单跳转
                return false;
            });

            //修改密码
            form.on('submit(updatePassBtn)', function(data) {

                if (data.field.pass != user.password){
                    layer.msg('原始密码输入错误');
                } else {
                    if (data.field.newPass != data.field.newrePass){
                        layer.msg('两次输入的新密码不一致');
                    } else {
                        $.ajax({
                            url: "/updateUserPass/" + user.uid + "/" + data.field.newPass,
                            type: "GET",
                            contentType: 'application/json',
                            dataType: 'json',
                            success: function(data) {
                                if (data) {
                                    layer.close(layer.index);
                                    layer.msg('修改成功');
                                    setTimeout('window.location.reload()',1000);
                                } else {
                                    layer.msg('修改失败');
                                }
                            },
                            error: function() {
                                console.log("ajax error");
                            }
                        });
                    }
                }
                // 阻止表单跳转
                return false;
            });

        });

        function exitLogin(){
            storage.setItem('user', null);
        }

    </script>
</body>
</html>
</html>